// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_17;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_17.CreativeRemote;
import com.google.api.ads.dfa.axis.v1_17.CreativeSaveResult;
import com.google.api.ads.dfa.axis.v1_17.HTMLCreativeAsset;
import com.google.api.ads.dfa.axis.v1_17.MobileDisplayCreative;
import com.google.api.ads.dfa.axis.v1_17.MobileDisplayCreativeAsset;

/**
 * This example creates a mobile display creative for a given advertiser or
 * campaign. If no campaign is specified then the creative is created at the
 * advertiser level. To get asset file names, run CreateHTMLAsset.java and
 * CreateImageAsset.java. To get a size ID, run GetSize.java. To get a creative
 * type ID, run GetCreativeType.java.
 *
 * Credentials and properties in {@code fromFile()} are pulled from the
 * "ads.properties" file. See README for more info.
 *
 * Tags: creative.saveCreative
 *
 * @author Joseph DiLallo
 */
public class CreateMobileCreative {

  public static void main(String[] args) throws Exception {
    long advertiserId = Long.parseLong("INSERT_ADVERTISER_ID_HERE");
    String creativeName = "INSERT_CREATIVE_NAME_HERE";
    String mobileAssetFileName = "INSERT_MOBILE_ASSET_FILE_NAME_HERE";
    long typeId = Long.parseLong("INSERT_TYPE_ID_HERE");

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the service.
    CreativeRemote service = new DfaServices().get(session, CreativeRemote.class);

    // Set mobile display creative structure.
    MobileDisplayCreative mobileDisplayCreative = new MobileDisplayCreative();
    mobileDisplayCreative.setAdvertiserId(advertiserId);
    mobileDisplayCreative.setName(creativeName);
    mobileDisplayCreative.setTypeId(typeId);
    mobileDisplayCreative.setArchived(false);

    // Set mobile creative asset.
    HTMLCreativeAsset htmlCreativeAsset = new MobileDisplayCreativeAsset();
    htmlCreativeAsset.setAssetFilename(mobileAssetFileName);
    mobileDisplayCreative.setCreativeAssets(new HTMLCreativeAsset[]{htmlCreativeAsset});

    // Create mobile display creative.
    CreativeSaveResult creativeSaveResult = service.saveCreative(mobileDisplayCreative, 0);

    // Display new creative ID.
    System.out.println("Mobile display creative with ID \""
        + creativeSaveResult.getId() + "\" was created.");
  }
}
